<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>考试第十题</title>
</head>

<body>
</body>
<script>
    /* 
        将数组[1,2,7,4,9,6,8,3,10,5]进行排序，
        升序结果为：[1,2,3,4,5,6,7,8,9,10]，
        倒序结果：[10,9,8,7,6,5,4,3,2,1]
     */
    //利用sort和箭头函数排序
    let array = [1, 2, 7, 4, 9, 6, 8, 3, 10, 5];
    document.write('升序结果为:' + array.sort((a, b) => a - b) + '<br/>');

    //冒泡排序
    let temp = 0;//临时存储值
    let array1 = [1, 2, 7, 4, 9, 6, 8, 3, 10, 5];
    for (let i = 0; i < array1.length; i++) {
        for (let j = 0; j < array1.length; j++) {
            if (array1[j] < array1[j + 1]) {
                temp = array1[j];
                array1[j] = array1[j + 1];
                array1[j + 1] = temp;
            }
        }
    }
    document.write('倒序结果为:' + array1);
</script>

</html>